import http from '@/api/request'

export default {
	state:{
		token:"",
		userInfo:{},
		permissions: [],
	},
	mutations:{
		setToken(state,token){
			state.token = token
			//uni.setStorageSync("token",token)
		},
		setUserInfo(state,userInfo){
			state.userInfo = userInfo
			//uni.setStorageSync("userInfo",userInfo)
		},
		clearInfo(state){
			state.token = ""
			state.userInfo = {}
			/*state = {
				token:"",
				userInfo:{},
			}*/
			//uni.clearStorageSync("token")
			//uni.clearStorageSync("userInfo")
		},
		SET_PERMISSIONS: (state, permissions) => {
			state.permissions = permissions
			//uni.setStorageSync('ruoyi_permissions', permissions) // 多端持久化
		}
	},
	actions: {
		async loadPerms({ commit }) {
			const res = await http({
				url: '/getInfo',
				method: 'get'
			})
			commit('SET_PERMISSIONS', res.permissions)
		}
	}
}